package com.fbli.controller;


import com.fbli.pojo.Users;
import com.fbli.service.UpdatePasswordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


//修改密码
@Controller
@ResponseBody
public class UpdatePasswordController {

    @Autowired
     private UpdatePasswordService updatePasswordService;

    String[] passwords = null;
    
    @RequestMapping(value = "/updatePassword",produces="text/html;charset=UTF-8;")
    public String updatePassword(Users users){
        //一个username
        //再加传来的password是3个数字连成的字符串

        //用，对密码进行拆分成密码数组

        passwords = users.getPassword().split(",");

        Users users1 = updatePasswordService.selectByUsername(users);
        String password = users1.getPassword();
        System.out.println(passwords[0].equals(password));
        System.out.println(passwords[0]==password);
        //判断当前用户数据库的密码和传过来的密码是否一致
     if(password.equals(passwords[0])){


            //判断要修改的密码两次是是否一致
            if (passwords[1].equals(passwords[2])){
                users.setPassword(passwords[1]);

                updatePasswordService.updatePassword(users);

                return "修改密码成功";

            }else{
                return "两次密码不一致";
            }



        }else{
            return " 密码错误";
        }




    }


}
